package com.formulas.certification.oauth.executor;

import com.formulas.certification.domain.oauth.model.OauthClientDetailsEntity;
import com.formulas.certification.dto.OauthClientDetailsDeleteCmd;
import com.formulas.certification.oauth.extensionpoint.OauthClientDetailsCheckExtPt;
import com.formulas.component.dto.Response;
import com.formulas.component.extension.BizScenario;
import com.formulas.component.extension.ExtensionExecutor;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @author yiwannuofulasi
 * @date 2023/6/15 10:16
 */
@Component
public class OauthClientDetailsDeleteCmdExe {

    @Resource
    private ExtensionExecutor extensionExecutor;

    public Response execute(OauthClientDetailsDeleteCmd cmd) {
        BizScenario bizScenario = cmd.getBizScenario();
        String clientId = cmd.getClientId();
        OauthClientDetailsEntity oauthClientDetailsEntity = extensionExecutor.execute(OauthClientDetailsCheckExtPt.class,
                bizScenario, extension -> extension.oauthClientDetailsCheck(clientId));
        cmd.setBizScenario(bizScenario);
        oauthClientDetailsEntity.deleteOauthClientDetails();
        return Response.buildSuccess();
    }
}
